<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace Plugin\Alarm\Http\Controller\Api;

use App\Http\Admin\Controller\AbstractController as AdminAbstractController;
use App\Http\Common\Middleware\AccessTokenMiddleware;
use App\Http\Common\Result;
use App\Http\CurrentUser;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Request;
use Hyperf\Swagger\Annotation\HyperfServer;
use Hyperf\Swagger\Annotation\JsonContent;
use Hyperf\Swagger\Annotation\Post;
use Hyperf\Swagger\Annotation\RequestBody;
use Mine\Swagger\Attributes\PageResponse;
use Plugin\Alarm\Http\Request\Admin\RdAlarmBroadcastRecordRequest;
use Plugin\Alarm\Service\RdAlarmBroadcastRecordService;

/**
 * 广播记录控制器
 * Class RdAlarmBroadcastRecordApiController
 */
#[HyperfServer(name: 'http')]
#[Middleware(middleware: AccessTokenMiddleware::class)]
final class RdAlarmBroadcastRecordApiController extends AdminAbstractController
{

    /**
     * 业务处理服务
     * RdAlarmBroadcastRecordService
     */
    public function __construct(
        protected readonly RdAlarmBroadcastRecordService $service,
        protected readonly CurrentUser                   $currentUser
    )
    {
    }

    #[Post(
        path: '/alarm/rdAlarmBroadcastRecord/api/shout',
        summary: '喊话控制器',
        security: [['Bearer' => [], 'ApiKey' => []]],
        tags: ['广播记录控制器'],
    )]
    #[RequestBody(
        content: new JsonContent(ref: RdAlarmBroadcastRecordRequest::class, title: '创建广播记录控制器')
    )]
    #[PageResponse(instance: new Result())]
    public function create(Request $request): Result
    {
        return $this->success(
            $this->service->shout(array_merge($request->all(), [
                'created_by' => $this->currentUser->id(),
            ]))
        );
    }

}